with System.Address_To_Access_Conversions;

package body PortAudioAda.ASIO is

   package SATA is
     new System.Address_To_Access_Conversions (ICS.char_array_access);

   --------------------------------
   -- PaAsio_GetInputChannelName --
   --------------------------------

   function PaAsio_GetInputChannelName
     (device       :        PaDeviceIndex;
      channelIndex :        Integer;
      error        : access PaError)
      return String
   is
      function Internal (d : PaDeviceIndex;
                         c : Integer;
                         n : System.Address)
                         return PaError;
      pragma Import (C, Internal, "PaAsio_GetInputChannelName");

      cn  : aliased ICS.char_array_access;
   begin
      error.all := Internal (device,
                             channelIndex,
                             SATA.To_Address (cn'Unchecked_Access));

      return s : String (1 .. Integer (ICS.Strlen (ICS.To_Chars_Ptr (cn)))) do
         s := ICS.Value (ICS.To_Chars_Ptr (cn));
      end return;
   end PaAsio_GetInputChannelName;

   ---------------------------------
   -- PaAsio_GetOutputChannelName --
   ---------------------------------

   function PaAsio_GetOutputChannelName
     (device       :        PaDeviceIndex;
      channelIndex :        Integer;
      error        : access PaError)
      return String
   is
      function Internal (d : PaDeviceIndex;
                         c : Integer;
                         n : System.Address)
                         return PaError;
      pragma Import (C, Internal, "PaAsio_GetOutputChannelName");

      cn  : aliased ICS.char_array_access;
   begin
      error.all := Internal (device,
                             channelIndex,
                             SATA.To_Address (cn'Unchecked_Access));

      return s : String (1 .. Integer (ICS.Strlen (ICS.To_Chars_Ptr (cn)))) do
         s := ICS.Value (ICS.To_Chars_Ptr (cn));
      end return;
   end PaAsio_GetOutputChannelName;

end PortAudioAda.ASIO;
